﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using tmAsk.Common;
using System.Web.UI.HtmlControls;

namespace tmAsk.Member
{
    public partial class Right : System.Web.UI.Page
    {
        tmAsk.Data.MakehtmlSQL sql = new tmAsk.Data.MakehtmlSQL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                function.CheckUserLogin();
                try
                {
                    string uid = function.Getcookies();
                    DataRow dr = sql.GetList("b_user", "u_id='" + uid + "'", "*").Tables[0].Rows[0];
                    txtEmail.Text = dr["u_email"].ToString();
                    txtNickName.Text = dr["u_nickName"].ToString();
                    lblAskNumber.Text = dr["u_askNumber"].ToString();
                    lblGood.Text = dr["u_goodNumber"].ToString();
                    lblRegTime.Text = dr["u_regTime"].ToString();
                    lblReviewNumber.Text = dr["u_reviewNumber"].ToString();
                    this.show_img.Src = alldata.Config_Path + dr["u_img"].ToString();
                }
                catch
                {
                    Response.Write(function.alert_text(2, "请重新登录", (new function()).Getlink("login", "")));
                    return;
                }
            }
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            function make_htm = new function();

            function.CheckUserLogin();
            try
            {
                string uid = function.Getcookies();
                HttpPostedFile userPostedFile = this.user_img.PostedFile;
                string img_name = "";

                if (userPostedFile != null)
                {
                    if (userPostedFile.ContentLength > 0)
                    {
                        img_name = make_htm.Upload("../uploadfiles/face/", 100, userPostedFile, "jpg,gif");
                        if (img_name.IndexOf("上传失败") >= 0)
                        {
                            Response.Write(function.alert_text(4, img_name, ""));
                            return;
                        }
                    }
                }
                string sqlstr = "update b_user set ";

                if (img_name != "")
                {
                    sqlstr += " u_img ='" + img_name + "',";
                }
                sqlstr += " u_email='" + function.HTMLEncode(txtEmail.Text.Trim().Replace("'", "")) + "',";
                sqlstr += " u_nickName='" + function.HTMLEncode(txtNickName.Text.Trim().Replace("'", "")) + "'";
                sqlstr += " where u_id='" + uid + "'";
                if (sql.ExecuteSql(sqlstr) > 0)
                {
                    Response.Write(function.alert_text(2, "保存成功!", "right.aspx"));
                }
            }
            catch
            {
                Response.Write(function.alert_text(2, "请重新登录!", (new function()).Getlink("login", "")));
                return;
            }
        }
    }
}